﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using HFK.DxFluentUITest.Dummy;
using HFK.DxFluentUITest.Dummy.DataObjects;
using HFK.DxFluentUI.Utility;
using HFK.DxFluentUI.VerticalGrid;
using MbUnit.Framework;
using DevExpress.XtraVerticalGrid;

namespace HFK.DxFluentUITest.VerticalGridControl
{
  [TestFixture]
  public class VerticalGridControlFactoryTestFixture
  {
    [Test]
    public void TestCreation()
    {
      VerticalGridWithEditorRows vgrid = new VerticalGridWithEditorRows();
      VGridControl verticalGrid = vgrid.Get;

      Assert.IsNotNull(verticalGrid);
    }

    [Test]
    public void TestAddRow()
    {
      VerticalGridWithEditorRows vgrid = new VerticalGridWithEditorRows();
      VGridControl verticalGrid = vgrid.Get;

      Assert.IsNotNull(verticalGrid);
      Assert.AreEqual(4, verticalGrid.Rows.Count);
      Assert.IsInstanceOfType(typeof(DevExpress.XtraVerticalGrid.Rows.EditorRow), verticalGrid.Rows[0]);
      Assert.AreEqual("Row1", verticalGrid.Rows[0].Properties.Caption);
      Assert.IsInstanceOfType(typeof(DevExpress.XtraVerticalGrid.Rows.EditorRow), verticalGrid.Rows[1]);
      Assert.AreEqual("Row2", verticalGrid.Rows[1].Properties.Caption);
      Assert.AreEqual("IntValue", verticalGrid.Rows[1].Properties.FieldName);
      Assert.IsInstanceOfType(typeof(DevExpress.XtraVerticalGrid.Rows.EditorRow), verticalGrid.Rows[2]);
      Assert.AreEqual("Row3", verticalGrid.Rows[2].Properties.Caption);
      Assert.AreEqual("IntValue", verticalGrid.Rows[2].Properties.FieldName);
      Assert.IsInstanceOfType(typeof(DevExpress.XtraVerticalGrid.Rows.EditorRow), verticalGrid.Rows[3]);
      Assert.AreEqual("Row4", verticalGrid.Rows[3].Properties.Caption);
      Assert.AreEqual("ShcData.DhcProperty.ThcProperty.StringProperty", verticalGrid.Rows[3].Properties.FieldName);
    }

    [Test]
    public void TestAddCategory()
    {
      VerticalGridWithCategoryRows vgrid = new VerticalGridWithCategoryRows();
      VGridControl verticalGrid = vgrid.Get;

      Assert.IsNotNull(verticalGrid);
      Assert.AreEqual(2, verticalGrid.Rows.Count);
      Assert.IsInstanceOfType(typeof(DevExpress.XtraVerticalGrid.Rows.CategoryRow), verticalGrid.Rows[0]);
      Assert.AreEqual("Category1", verticalGrid.Rows[0].Properties.Caption);
      Assert.IsInstanceOfType(typeof(DevExpress.XtraVerticalGrid.Rows.CategoryRow), verticalGrid.Rows[1]);
      Assert.AreEqual("Category2", verticalGrid.Rows[1].Properties.Caption);
      Assert.AreEqual(2, verticalGrid.Rows[1].ChildRows.Count);
      Assert.IsInstanceOfType(typeof(DevExpress.XtraVerticalGrid.Rows.CategoryRow), verticalGrid.Rows[1].ChildRows[0]);
      Assert.AreEqual("Category21", verticalGrid.Rows[1].ChildRows[0].Properties.Caption);
      Assert.IsInstanceOfType(typeof(DevExpress.XtraVerticalGrid.Rows.EditorRow), verticalGrid.Rows[1].ChildRows[1]);
      Assert.AreEqual("Category2Row1", verticalGrid.Rows[1].ChildRows[1].Properties.Caption);
    }

  }
}
